<?php
header("Access-Control-Allow-Origin:*");
require_once('dbServerConnect.php');
$con = new DB();
$link = $con->mySqlServer();
$blogId = $_GET['blog_id'];
if ($link && $blogId) {
    $sql = "select * from blog_container where id='$blogId' limit 1";
    $res = executeSql($link, $sql);
    $tag = $res[0][6];
    $id = $res[0][0];
    result($tag, $id, $res, $link);
} else {
    $res = array('status' => 0,'message'=>'获取数据失败','erro'=> $link,$blogId);
}

function result($tag, $id, $res, $link) {
    // 随机返回5条相关类型文章,id!='$id'：过滤当前已经展示的文章
    $sql = "select * from blog_container where tag='$tag' AND id!='$id' order by RAND() limit 5";
    $data = executeSql($link, $sql);
    $result = array('status' => 1,'data'=>$res[0], 'similarContent'=> $data);
    echo json_encode($result);
}

// 执行Sql语句
function executeSql($link, $sql) {
    $result = mysqli_query($link, $sql);
    $data = mysqli_fetch_all($result);
    return $data;
}
